<?php
class DB{
	private static $host = 'localhost';
	private static $username = '';
	private static $password = '';
	private static $database = '';
	
	private static $connection = null;
	
	public static function setHost($host){
		self::$host = $host;
	}
	
	public static function connect($username, $password, $database){
		if(self::isConnected())return;
		self::$username = $username;
		self::$password = $password;
		self::$database = $database;
		self::_connect();
	}
	
	public static function setUserInfo($username, $password, $database){
		self::$username = $username;
		self::$password = $password;
		self::$database = $database;
	}
	
	private static function _connect(){
		self::$connection = new mysqli(self::$host, self::$username, self::$password, self::$database);
	}
	
	public static function isConnected(){
		return self::$connection != null;
	}
	
	public static function getMySQLi(){
		if(!self::isConnected()){
			self::_connect();
		}
		return self::$connection;
	}
	
	public static function query($query){
		if(!self::isConnected()){
			self::_connect();
		}
		return self::$connection->query($query);
	}
	
	public static function safe($str){
		if(!self::isConnected()){
			self::_connect();
		}
		return self::$connection->real_escape_string($str);
	}
	
	public static function close(){
		if(self::isConnected()){
			self::$connection->close();
		}
	}
}

?>